home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 17 / CU Amiga Magazine's Super CD-ROM 17 (1997)(EMAP Images)(GB)[!][issue 1997-12].iso / CUCD / Programming / DiceSource / src / dme / filereq.c < prev    next >
C/C++ Source or Header  |  1997-09-09  |  6KB  |  299 lines

  1. /*
  2.  *    (c)Copyright 1992-1997 Obvious Implementations Corp.  Redistribution and
  3.  *    use is allowed under the terms of the DICE-LICENSE FILE,
  4.  *    DICE-LICENSE.TXT.
  5.  */
  6.  
  7. /*
  8.  *  ASL interface
  9.  *  ARP interface
  10.  */
  11.  
  12. #include "defs.h"
  13. #include <stdarg.h>
  14. #include <libraries/asl.h>
  15. #include <proto/asl.h>
  16.  
  17. Prototype void do_arpinsfile (void);
  18. Prototype void do_arpload (void);
  19. Prototype void do_arpsave (void);
  20. Prototype void fixfile (char *, char *);
  21. Prototype void splitpath (char *, char *, char *);
  22.  
  23. Prototype void do_aslload(void);
  24. Prototype void do_aslsave(void);
  25. Prototype void do_aslinsfile(void);
  26. Prototype void do_aslfont(void);
  27.  
  28. /*
  29.  *  The ASL interface uses the asl.library if it exists, else tries to
  30.  *  use the ARP interfafce.
  31.  */
  32.  
  33. void
  34. do_aslload()
  35. {
  36.     char file[64];
  37.     char dir[64];
  38.  
  39.     BPTR oldlock = CurrentDir((BPTR)Ep->dirlock);
  40.  
  41.     splitpath(Ep->Name, file, dir);
  42.  
  43.     if (FReq) {            /* If we have asl.library & requester */
  44.     if (AslRequestTags((APTR)FReq,
  45.                 ASL_Hail,        "DME Load New File",
  46.                 ASL_OKText,     "Load",         /* ASL_Window, window,    ASL_FuncFlags, ((win)&&(win->UserPort)) ? 0 : FILF_NEWIDCMP,*/
  47.                 ASL_FuncFlags,  FILF_NEWIDCMP,  /* no window tag */
  48.                 ASL_Dir,        dir,
  49.                 ASL_File,        file,
  50.                 TAG_DONE )) {
  51.  
  52.         BPTR newlock;
  53.  
  54.         if (newlock = Lock( FReq->rf_Dir, SHARED_LOCK)) {
  55.         UnLock(CurrentDir(oldlock));
  56.         Ep->dirlock = (long)newlock;
  57.         /* fixfile(FReq->rf_File,FReq->rf_Dir); */
  58.         av[0] = (ubyte *)"n";
  59.         av[1] = (ubyte *) FReq->rf_File;
  60.         do_edit();
  61.         return;
  62.         }
  63.     }
  64.     CurrentDir(oldlock);
  65.     } else {          /* no asl.library? try ARP */
  66.     do_arpload();
  67.     }
  68. }
  69.  
  70.  
  71. void
  72. do_aslsave()
  73. {
  74.     char file[64];
  75.     char dir[64];
  76.     BPTR oldlock = CurrentDir((BPTR)Ep->dirlock);
  77.  
  78.     splitpath(Ep->Name, file, dir);
  79.     if (FReq) {
  80.     if (AslRequestTags( (APTR)FReq,
  81.                 ASL_Hail,        "DME Save File",
  82.                 ASL_OKText,     "Save",
  83.                 ASL_FuncFlags,  FILF_NEWIDCMP | FILF_SAVE,    /* no window tag! */
  84.                 ASL_Dir,        dir,
  85.                 ASL_File,        file,
  86.                 TAG_DONE )) {
  87.  
  88.         CurrentDir(oldlock);
  89.         fixfile( FReq->rf_File, FReq->rf_Dir);
  90.         av[1] = (ubyte *)FReq->rf_File;
  91.         do_saveas();
  92.     } else {
  93.         CurrentDir(oldlock);
  94.     }
  95.     } else {
  96.     do_arpsave();
  97.     }
  98. }
  99.  
  100. void
  101. do_aslinsfile()
  102. {
  103.     char file[64];
  104.     char dir[64];
  105.     BPTR oldlock = CurrentDir((BPTR)Ep->dirlock);
  106.  
  107.     splitpath(Ep->Name, file, dir);
  108.     if (FReq) {
  109.     if (AslRequestTags( (APTR)FReq,
  110.                 ASL_Hail,        "DME Insert File",
  111.                 ASL_OKText,     "Load",
  112.                 ASL_FuncFlags,  FILF_NEWIDCMP,  /* no window tag */
  113.                 ASL_Dir,        dir,
  114.                 ASL_File,        file,
  115.                 TAG_DONE )) {
  116.  
  117.         CurrentDir(oldlock);
  118.         fixfile( FReq->rf_File, FReq->rf_Dir);
  119.         av[0] = (ubyte *)"i";
  120.         av[1] = (ubyte *)FReq->rf_File;
  121.         do_edit();
  122.         return;
  123.     }
  124.     CurrentDir(oldlock);
  125.     } else {
  126.     do_arpinsfile();
  127.     }
  128. }
  129.  
  130. /*
  131.  *  DICE 2.06.17 won't allow FontTags[] inside do_aslfont(),
  132.  *  I wanted to put it after *fontreq, below....
  133.  */
  134.  
  135. struct TagItem FontTags[] = {    ASL_Hail,    (ULONG)"DME fixed width font",
  136.                 ASL_FuncFlags,    FONF_FIXEDWIDTH,
  137.                 ASL_MinHeight,    6,
  138.                 ASL_MaxHeight,    24,    /* >reasonable, eh? */
  139.                 TAG_DONE };
  140.  
  141. void
  142. do_aslfont()
  143. {
  144.     if (FReq) {
  145.     struct FontRequester *fontreq;
  146.  
  147.     if (fontreq = (struct FontRequester *)
  148.               AllocAslRequest(ASL_FontRequest,FontTags) ) {
  149.  
  150.         if (AslRequest(fontreq, NULL)) {
  151.  
  152.         /*  Since we have GetFont() already, just pass
  153.          *   the name and size from fontreq's TextAttr to it.
  154.          *
  155.          *  What follows mimics SETFONT (in cmnd3.c)
  156.          */
  157.  
  158.         FONT *font = (FONT *)GetFont( fontreq->fo_Attr.ta_Name,
  159.                          (short) fontreq->fo_Attr.ta_YSize );
  160.         ED *ep = Ep;
  161.         if (font) {
  162.             text_sync();
  163.             if (ep->Font)
  164.             CloseFont(ep->Font);
  165.             ep->Font = font;
  166.             SetFont(ep->Win->RPort, font);
  167.             SetRast(ep->Win->RPort, 0);
  168.             RefreshWindowFrame(ep->Win);
  169.             set_window_params();
  170.             text_redisplay();
  171.         } else {
  172.             title("Unable to find font");
  173.         }
  174.         }
  175.         FreeAslRequest(fontreq);
  176.     }
  177.     } else {
  178.     title("Need ASL.LIBRARY for Font Requester!");
  179.     }
  180. }
  181.  
  182.  
  183. void
  184. do_arpinsfile()
  185. {
  186.     char file[64];
  187.     char dir[64];
  188.     BPTR oldlock = CurrentDir((BPTR)Ep->dirlock);
  189.  
  190.     splitpath(Ep->Name, file, dir);
  191.     if (arpreq("Insert File", file, dir, NULL)) {
  192.     CurrentDir(oldlock);
  193.     fixfile(file, dir);
  194.     av[0] = (ubyte *)"i";
  195.     av[1] = (ubyte *)file;
  196.     do_edit();
  197.     return;
  198.     }
  199.     CurrentDir(oldlock);
  200. }
  201.  
  202. void
  203. do_arpload()
  204. {
  205.     char file[64];
  206.     char dir[64];
  207.     BPTR oldlock = CurrentDir((BPTR)Ep->dirlock);
  208.  
  209.     splitpath(Ep->Name, file, dir);
  210.     if (arpreq("New File", file, dir, NULL)) {
  211.     BPTR newlock;
  212.     if (newlock = Lock(dir, SHARED_LOCK)) {
  213.         UnLock(CurrentDir(oldlock));
  214.         Ep->dirlock = (long)newlock;
  215.         /*
  216.         fixfile(file,dir);
  217.         */
  218.         av[0] = (ubyte *)"n";
  219.         av[1] = (ubyte *)file;
  220.         do_edit();
  221.         return;
  222.     }
  223.     }
  224.     CurrentDir(oldlock);
  225. }
  226.  
  227. void
  228. do_arpsave()
  229. {
  230.     char file[64];
  231.     char dir[64];
  232.     BPTR oldlock = CurrentDir((BPTR)Ep->dirlock);
  233.  
  234.     splitpath(Ep->Name, file, dir);
  235.     if (arpreq("Save File", file, dir, NULL)) {
  236.     CurrentDir(oldlock);
  237.     fixfile(file,dir);
  238.     av[1] = (ubyte *)file;
  239.     do_saveas();
  240.     } else {
  241.     CurrentDir(oldlock);
  242.     }
  243. }
  244.  
  245. void
  246. fixfile(file,dir)
  247. char *file,*dir;
  248. {
  249.     char *ptr;
  250.     short len = strlen(dir);
  251.     char hasdev = 0;
  252.  
  253.     /*
  254.      *    do we need to add a slash to the directory spec?
  255.      */
  256.  
  257.     if (len && dir[len-1] != '/' && dir[len-1] != ':') {
  258.     dir[len++] = '/';
  259.     dir[len] = 0;
  260.     }
  261.  
  262.     /*
  263.      *    Is file spec really a full path spec?
  264.      */
  265.  
  266.     for (ptr = file; *ptr; ++ptr) {
  267.     if (ptr[0] == ':')
  268.         hasdev = 1;
  269.     }
  270.     if (!hasdev) {
  271.     movmem(file,file+len,strlen(file)+1);
  272.     movmem(dir,file,len);
  273.     }
  274. }
  275.  
  276. /*
  277.  *  Search backwards for first ':' or '/' and split path there.
  278.  *  This subroutine may appear to be coded incorrectly to a novice
  279.  *  programmer.  It isn't [now].
  280.  */
  281.  
  282. void
  283. splitpath(name, file, dir)
  284. char *name;
  285. char *file, *dir;
  286. {
  287.     short i;
  288.  
  289.     for (i = strlen(name); i >= 0; --i) {    /* was (incorrectly) "i > 0" */
  290.     if (name[i] == ':' || name[i] == '/')
  291.         break;
  292.     }
  293.     ++i;
  294.     strcpy(file, name + i);
  295.     movmem(name, dir, i);
  296.     dir[i] = 0;
  297. }
  298.  
  299.